<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios常用配置以及默认配置</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
</head>
<body>
    <button>王者荣耀</button>
    <button>英雄联盟</button>
    <script>
        let btns = document.querySelectorAll('button');

        //设置默认的配置
        axios.defaults.method = 'get';
        axios.defaults.baseURL = 'http://api.xiaohigh.com';

        //绑定事件
        btns[0].onclick = async function(){
            let {data} = await axios({
                url: '/heros'
            });
            console.log(data);
        }

        //绑定事件
        btns[1].onclick = async function(){
            //发送请求
            // let {data} = await axios({
            //     url: '/lol'
            // });
            //对象方法调用, 同样适用
            let {data} = await axios.get('/lol');
            //输出
            console.log(data);
        }
    </script>
</body>
</html>